package com.hmyd.hmyd_android.ui;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.commons.UrlConstant;
import com.hmyd.hmyd_android.utils.MyToast;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * 冻结账号
 * 
 * @author wangc
 * 
 */
@ContentView(R.layout.activity_forzenaccount)
public class ForzenAccountActivity extends BasicActivity {
	// 标题栏
	@ViewInject(R.id.home_title)
	public View home_title;
	@ViewInject(R.id.home_title_txt)
	public TextView home_title_txt;
	@ViewInject(R.id.home_right)
	public TextView home_right;

	// 交易密码
	@ViewInject(R.id.password)
	private EditText mEdPasswd;
	// 开始冻结
	@ViewInject(R.id.submit)
	private Button submit;

	private static int SUBMMIT = 1;

	@OnClick(R.id.submit)
	public void Onclick(View view) {
		switch (view.getId()) {
		case R.id.submit:
			String passwd = mEdPasswd.getText().toString().trim();
			if (TextUtils.isEmpty(passwd)) {
				MyToast.showHMToast(ForzenAccountActivity.this, false, "请输入登录密码");
				return;
			}

			RequestParams params = new RequestParams();
			params.addBodyParameter("traderPassword", mEdPasswd.getText().toString());
			onRequest(SUBMMIT, UrlConstant.FORZENACCOUNT, HttpMethod.POST, params);
			break;
		default:
			break;
		}

	}

	private TextWatcher watcher = new TextWatcher() {
        
        @Override    
        public void afterTextChanged(Editable s) {
        }   
          
        @Override 
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }  
 
         @Override    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        	 if(TextUtils.isEmpty(s)){
        		 submit.setEnabled(false);
        	 }else{
        		 submit.setEnabled(true);
        	 }
        }                    
    };
	
	@Override
	public void onPostSuccess(int postId, String msg) {
		JSONObject jsonObject;
		try {
			jsonObject = new JSONObject(msg);
			MyToast.showHMToast(this, true, jsonObject.getString("info"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		startActivity(new Intent(this, MainActivity.class));
		Log.e("TAGSuccess", msg.toString());
	}

	@Override
	public void onPostFailure(int postId, String msg) {
		Log.e("TAGFailure", msg.toString());
	}

	@Override
	protected void setParams() {
		home_title_txt.setText("冻结账号");
		home_title.setOnTouchListener(touch);
		mEdPasswd.addTextChangedListener(watcher);
	}

	@Override
	protected void leftButton() {
		AppBasic.getInstance().finishCurrentActivity();
	}

	@Override
	protected void rightButton() {

	}

}
